package com.chixing.service.impl;

import com.chixing.mapper.CustomerMapper;
import com.chixing.pojo.Customer;
import com.chixing.pojo.CustomerExample;
import com.chixing.service.LoginCustomerService;
import com.chixing.util.MD5Utils;
import com.chixing.util.ServerResponse;
import org.mindrot.jbcrypt.BCrypt;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.management.Query;
import java.util.List;

@Service
public class LoginCustomerServiceImpl implements LoginCustomerService {
    @Autowired
    private CustomerMapper customerMapper;
    @Override
    public ServerResponse Login(Long custTel, String custPassword) {
        CustomerExample customerExample = new CustomerExample();
        customerExample.createCriteria().andCustTelEqualTo(custTel);
        String newPassword = MD5Utils.formPassToDBPass(custPassword,MD5Utils.SALT);
        List<Customer> customerList = customerMapper.selectByExample(customerExample);
        Customer customer1 = null;
        if(customerList.size()>0) {
            customer1 = customerList.get(0);
            String pwd = customer1.getCustPassword();
            if(pwd.equals(newPassword)){
                return ServerResponse.getSuccess(customer1);
            }else {
                return ServerResponse.getFail(null);
            }
        }
        return ServerResponse.getFail(null);
    }
}
//                注册的密码d3f2a61d18fbb68970a862d3ca79746d
//最终持久化到数据库中的密码是：cedbb232d58fc2495f119c28511e77ba